package hn.cch.spring.bean.scope.component;

import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

@Component
public class BeanSingleton {

    // 在单例bean中依赖注入其他作用域bean会失效的，使用prototype举例
    @Autowired
    private BeanPrototype0 beanPrototype0;

    @Lazy
    @Autowired
    private BeanPrototype1 beanPrototype1;

    @Autowired
    private BeanPrototype2 beanPrototype2;

    @Autowired
    private ObjectFactory<BeanPrototype3> beanPrototype3;

    @Autowired
    private ApplicationContext applicationContext;

    public BeanPrototype4 getBeanPrototype4(){
        return applicationContext.getBean(BeanPrototype4.class);
    }

    public BeanPrototype0 getBeanPrototype0() {
        return beanPrototype0;
    }

    public void setBeanPrototype0(BeanPrototype0 beanPrototype0) {
        this.beanPrototype0 = beanPrototype0;
    }

    public BeanPrototype1 getBeanPrototype1() {
        return beanPrototype1;
    }

    public void setBeanPrototype1(BeanPrototype1 beanPrototype1) {
        this.beanPrototype1 = beanPrototype1;
    }

    public BeanPrototype2 getBeanPrototype2() {
        return beanPrototype2;
    }

    public void setBeanPrototype2(BeanPrototype2 beanPrototype2) {
        this.beanPrototype2 = beanPrototype2;
    }

    public ObjectFactory<BeanPrototype3> getBeanPrototype3() {
        return beanPrototype3;
    }

    public void setBeanPrototype3(ObjectFactory<BeanPrototype3> beanPrototype3) {
        this.beanPrototype3 = beanPrototype3;
    }
}
